﻿using MyAspx.EasyFramework.DAL3;
using MyAspx.EasyFramework.EntityFramework;
using MyAspx.Framework.WebUnit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebUI.Form
{
    public partial class UserLogin : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void loginClick(object sender, EventArgs e)
        {
            //UserDAL _userdal = new UserDAL();
            //MyAspx.EasyFramework.EntityFramework.my_users _my_users = new MyAspx.EasyFramework.EntityFramework.my_users();
            //_my_users.useregname = user.Value;
            //_my_users.userpwd = pwd.Value;
            //if (_userdal.ValidateUser(_my_users) == "find")
            //{
            //    Session["myaspxuser"] = user;
            //    //Page.RegisterClientScriptBlock("alertnewmesuser", "<script>layer.alert('用户名密码不对！')</script>");
                
            //}
            //else
            //{
            //    Page.RegisterClientScriptBlock("alertnewmesuser", "<script>layer.alert('用户名密码不对！')</script>");
                
            //    //return "用户名密码不对！";
            //}
        }

     

        protected void yzmbtnhiddle_Click(object sender, EventArgs e)
        {
         
        }
        [WebMethod(true)]
        public static  string LoginUser(string user, string pwd)
        {
            UserDAL _userdal = new UserDAL();
            MyAspx.EasyFramework.EntityFramework.my_users _my_users = new MyAspx.EasyFramework.EntityFramework.my_users();
            _my_users.useregname = user;
            _my_users.userpwd = pwd;
            var userid = _userdal.getUserid(user);
            var ip = IpHelper.getClientIp;
            var datetime = DateTime.Now;
            try
            {
 commyaspxdbEntities _commyaspxdbEntities = new commyaspxdbEntities();
            _commyaspxdbEntities.my_logindetail.Add(new my_logindetail() { 
            loginip= ip,
            loginTime=datetime,
            loginuserid = userid
            });
            _commyaspxdbEntities.SaveChanges();
            }
            catch (Exception)
            {
                //throw;
            }
            if (_userdal.ValidateUser(_my_users) == "find")
            {
                HttpContext.Current.Session["myaspxuser"] = user;
                 //Session["myaspxuser"] = user;
                return "ok";
            }
            else
            {
                return "用户名密码不对！";
            }

        }
    }
}